package conf

import "sort"

//二分查找法
func BinarySearch(arr []int64, v int64) int {
	sort.Slice(arr, func(i, j int) bool { return arr[i] < arr[j] })
	left := 0
	right := len(arr) - 1

	for left <= right {
		mid := (left + right) / 2
		if v == arr[mid] {
			return mid
		}
		if arr[mid] > v {
			right = mid - 1
		} else if arr[mid] < v {
			left = mid + 1
		}
	}
	return -1
}
